#include "dataqueue.h"
#include <QMutexLocker>
#include <QDebug>

DataQueue * DataQueue::instance = nullptr;
DataQueue &DataQueue::getInstance()
{
    if(nullptr == instance){
        instance = new DataQueue();
    }
    return *instance;
}

QString DataQueue::getData()
{
    QMutexLocker lock(&mutex);
    if(dataQueue.empty()){
        return "";
    }

    QString data = dataQueue.front();
    dataQueue.pop();
    return data;
}

bool DataQueue::setData(const QString &data)
{
    QMutexLocker lock(&mutex);
    if(dataQueue.size() >= 10){
        return false;
    }

    qDebug()<<QStringLiteral("放入队列")<< data;
    dataQueue.push(data);
    return true;
}
